<template>
	<view class="con">
		<u-notify ref="uNotify" message="Hi uView"></u-notify>
		<u--textarea v-model="dy_url" placeholder="请输入链接"></u--textarea>
		<u-button type="primary" text="图标按钮" @click="clearMark" class="btn">去除水印</u-button>
		<view>
			<video id="myVideo" :src='url_' @error="videoErrorCallback" :danmu-list="danmuList" enable-danmu danmu-btn
				controls></video>
		</view>
		<u-button type="primary" text="图标按钮" @click="downLoad" class="btn">下载该视频</u-button>
		<view>
			视频和音频链接，(点击直接复制)可复制到浏览器下载：
		</view>

		<view class="video_url" @click="copy(video_url)">
			{{video_url}}
		</view>
		<view class=" video_url" @click="copy(audio_url)">
			{{ audio_url}}
		</view>
	</view>
</template>

<script>
	import cloudApi from '../../common/cloudApi.js'
	export default {
		data() {
			return {
				video_url: '',
				audio_url: '',
				dy_url: '',
				url_: '',
				current: {
					poster: 'https://bjetxgzv.cdn.bspapp.com/VKCEYUGU-uni-app-doc/7fbf26a0-4f4a-11eb-b680-7980c8a877b8.png',
					name: '提取音频',
					author: '暂无',
					src: '',
				},
				audioAction: {
					method: 'pause'
				}
			}
			// share: {
			// 	title: '好玩的小程序',
			// 	path: '/pages/mine/mine',
			// },
		},
		methods: {
			copy(value) {
				uni.setClipboardData({
					data: value,
					success: function() {
						console.log('success');
					}
				})
			},
			clearMark() {
				console.log('clear'),
					cloudApi.call({
						name: 'clearVideoMark',
						data: {
							dyurl: this.dy_url.replace(/(^\s*)|(\s*$)/g, "")
						},
						success: res => {
							console.log('res', res)
							this.url_ = res.result.video
							this.video_url = res.result.video
							this.audio_url = res.result.music
						}
					})
			},
			downLoad() {
				uni.saveVideoToPhotosAlbum({
					filePath: this.url_,
					success: function() {
						console.log('save success');
					}
				});
				// uni.downloadFile({
				// 	url: this.url_,
				// 	success: (res) => {
				// 		console.log(res);
				// 		uni.saveVideoToPhotosAlbum({
				// 			filePath: res.tempFilePath,
				// 			success: () => {
				// 				console.log('save success');
				// 				console.log('下载成功');
				// 				this.$refs.uNotify.show({
				// 					top: 0,
				// 					type: 'error',
				// 					color: '#fff',
				// 					bgColor: '#096',
				// 					message: '下载成功！请到相册进行查看',
				// 					duration: 1000 * 2,
				// 					fontSize: 16,
				// 					safeAreaInsetTop: false
				// 				})
				// 			}
				// 		});
				// 	}
				// });
			}
		}
	}
</script>
<style lang="scss">
	.btn {
		margin: 40rpx 0rpx 50rpx;
	}

	.video_url {
		width: 100%;
		margin: 20rpx 0rpx;
		color: #0066CC;
		font-size: 30rpx;
		word-wrap: break-word;
		word-break: normal;
	}
</style>
